<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>if和for不推荐一起使用</h2>

      <!-- 判断条件和item有关的情况下，可以使用计算属性先过滤再循环 -->
      <!-- <p v-for="item in oddList">{{ item }}</p> -->

      <!-- 判断条件和item无关的情况下，可以将v-if提到外层 -->
      <template v-if="show">
        <p v-for="item in list">{{ item }}</p>
      </template>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            list: [1, 2, 3, 4, 5, 6, 7],
            show: true,
          };
        },
        computed: {
          oddList() {
            return this.list.filter((item) => item % 2);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
